
package com.team2.cyber_eye.ActivityHelpers;


import com.team2.cyber_eye.Home;
import com.team2.cyber_eye.R;
import com.team2.shared.HistoryItem;

import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class HistoryListAdapter extends BaseAdapter {

    private Home homeActivity;

    private LayoutInflater layoutInflater;

    public HistoryListAdapter(Home homeActivity) {
        this.homeActivity = homeActivity;
        layoutInflater = homeActivity.getLayoutInflater();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        HistoryItem item = (HistoryItem) getItem(position);

        View result = null;
        if (convertView == null) {
            result = layoutInflater.inflate(R.layout.item_history, null);
        } else {
            result = convertView;
        }
        ImageView iv = (ImageView) result.findViewById(R.id.historyItemIv);
        
        /*Matrix matrix = new Matrix();
		matrix.postRotate(90);
		Bitmap rotatedBitmap = Bitmap.createBitmap(item.getThumb(), 0, 0, 
				item.getThumb().getWidth(), item.getThumb().getHeight(), matrix, true);*/
		
        iv.setImageBitmap(item.getThumb());
        TextView tv = (TextView) result.findViewById(R.id.historyItemTv);
        tv.setText(item.getLabel());

        return result;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return Home.getHistory().get(Home.getHistory().size() - 1 - position);
    }

    @Override
    public int getCount() {
        return Home.getHistory().size();
    }

    public HistoryItem removeItem(int position) {
        return Home.getHistory().remove(Home.getHistory().size() - 1 - position);
    }

}
